/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package smsku;

import java.sql.Statement;
import javax.swing.JOptionPane;
import javax.swing.table.DefaultTableModel;

/**
 *
 * @author Heri Setiyawan
 */
public class cGuestBook {
    public String test_id,nama,alamat;
    koneksi ko = new koneksi();
    
    public cGuestBook(){
        ko.getKoneksi();
    }

    public String getTest_id() {
        return test_id;
    }

    public void setTest_id(String test_id) {
        this.test_id = test_id;
    }

    public String getNama() {
        return nama;
    }

    public void setNama(String nama) {
        this.nama = nama;
    }

    public String getAlamat() {
        return alamat;
    }

    public void setAlamat(String alamat) {
        this.alamat = alamat;
    }
    
    public Boolean insert(){
        String sql = "insert into test set nama='"+nama+"',alamat='"+alamat+"'";
        Boolean i=false;
          try{
            Statement st = ko.conn.createStatement();
            st.executeUpdate(sql);
            //this.Notifnya("input berhasil");
            i=true;
        }catch(Exception e){
            this.Notifnya("Gagal insert"+e);
        }
          return i;
    }
    
    public DefaultTableModel viewAll(){
    
        String title[] = {"id","nama","alamat"};
        String sql = "select * from test";
        DefaultTableModel dtm = new DefaultTableModel(null,title);
        try{
            ko.rs = ko.stt.executeQuery(sql);
            String data[] = new String[3];
            while(ko.rs.next()){
                data[0]=ko.rs.getString(1);
                data[1]=ko.rs.getString(2);
                data[2]=ko.rs.getString(3);
                dtm.addRow(data);
            }
        }catch(Exception e){
            this.Notifnya("Gagal diview "+e);
        }
        return dtm;
    }
    
    public void Notifnya(String notif){
        JOptionPane.showMessageDialog(null,notif,"Error Message",JOptionPane.OK_OPTION);
    }
}
